package cn.waxcc.controller;

import cn.waxcc.pojo.HrsPatientregistration;
import cn.waxcc.service.HrsPatientregistrationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: springboot-medicalapp
 * @ClassName HrsPatientregistrationController
 * @description:
 * @author: JYF
 * @create: 2023-04-11 10:44
 * @Version 1.0
 */
@Api(tags = "健康卡管理")
@Controller
@CrossOrigin(origins = "*")
@RequestMapping("/hrs")
public class HrsPatientregistrationController {

    @Autowired
    private HrsPatientregistrationService hrsPatientregistrationService;

    @RequestMapping("/all")
    @ResponseBody
    public List<HrsPatientregistration> findAllHrsPatientregistration() {
        System.out.println(hrsPatientregistrationService.findAllHrsPatientregistration());
        return hrsPatientregistrationService.findAllHrsPatientregistration();
    }

    @PostMapping("/insert")
    @ResponseBody
    public int insert(HrsPatientregistration hrsPatientregistration) {
        int inset = hrsPatientregistrationService.inset(hrsPatientregistration);
        return inset;
    }

    @GetMapping("/byStatusid/{statusid}")
    @ResponseBody
    public HrsPatientregistration findByStatusid(@PathVariable String statusid) {
        return hrsPatientregistrationService.findByStatusid(statusid);
    }

    @RequestMapping("/allByPage")
    @ResponseBody
    public List<HrsPatientregistration> allBookByPage(Integer pageNum,
                                Integer pageSize,//@RequestParam(defaultValue = "5") 设置默认页面大小为5
                                Model model){
        //为了程序的严谨性，判断非空：
        if(pageNum == null){//若pageNum为空
            pageNum = 1;   //设置默认当前页为1
        }
        if(pageNum <= 0){  //若为负数
            pageNum = 1;   //设置默认值为1
        }
        if(pageSize == null){ //若页面大小为空
            pageSize = 8;    //设置默认每页显示的数据数
        }
        List<HrsPatientregistration> hrsPatientregistrations;
        try {
            //调用分页查询的方法
            hrsPatientregistrations = hrsPatientregistrationService.queryHrsPatientregistrationByPage(pageNum, pageSize);
        }finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        return hrsPatientregistrations;
    }

    @RequestMapping("/delBypId")
    @ResponseBody
    public Integer delBypId(Integer pId) {
        return hrsPatientregistrationService.delBypId(pId);
    }

    @RequestMapping("/queryBypName")
    @ResponseBody
    public  List< HrsPatientregistration> queryBypName(String pName) {
        return hrsPatientregistrationService.queryBypName(pName);
    }

    @PostMapping("/updateBypId")
    @ResponseBody
    public Integer updateBypId(HrsPatientregistration hrsPatientregistration) {
        return hrsPatientregistrationService.updateBypId(hrsPatientregistration);
    }

    @RequestMapping("/queryBypId")
    @ResponseBody
    public HrsPatientregistration queryBypId(Integer pId) {
        return hrsPatientregistrationService.queryBypId(pId);
    }


}
